package framework.fastdevelop.com.touch.group;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import framework.fastdevelop.com.touch.R;

public class RefreshHeader extends FrameLayout {
    private View headerView;
    private TextView tv_refresh_header_lable;

    public RefreshHeader(Context context) {
        super(context);

        initHeader(context);
    }

    private void initHeader(final Context context) {
        headerView = LayoutInflater.from(context).inflate(R.layout.include_refresh_header, null);
        tv_refresh_header_lable = (TextView) headerView.findViewById(R.id.tv_refresh_header_lable);
        addView(headerView, RelativeLayout.LayoutParams.MATCH_PARENT, getDefaultHeight());
    }

    public int getDefaultHeight() {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, getContext().getResources().getDisplayMetrics());
    }

    public void refreshState(RefreshLayout.RefreshState refreshState){
        if(RefreshLayout.RefreshState.Pulling.equals(refreshState)){
            tv_refresh_header_lable.setText("下拉刷新");
        }else if(RefreshLayout.RefreshState.Release.equals(refreshState)){
            tv_refresh_header_lable.setText("松手立即刷新");
        }else if(RefreshLayout.RefreshState.Refreshing.equals(refreshState)){
            tv_refresh_header_lable.setText("刷新中");
        }else if(RefreshLayout.RefreshState.Success.equals(refreshState)){
            tv_refresh_header_lable.setText("刷新成功");
        }else{
            // refresh failed
            tv_refresh_header_lable.setText("刷新失败");
        }
    }
}
